package com.aaa.market.controller;

import com.aaa.common.util.Result;
import com.aaa.market.entity.Advertise;
import com.aaa.market.entity.Coupon;
import com.aaa.market.service.AdvertiseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 广告位(Advertise)表控制层
 *
 * @author YuXin
 * @since 2020-11-25 15:41:00
 */
@RestController
@RequestMapping("advertise")
public class AdvertiseController {
    /**
     * 服务对象
     */
    @Resource
    private AdvertiseService advertiseService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("queryById")
    public Advertise queryById(Long id) {
        return this.advertiseService.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param advertise 模糊查询条件
     * @return 对象列表
     */
    @PostMapping("queryAll")
    public List<Advertise> queryAll(@RequestBody Advertise advertise) {
        return this.advertiseService.queryAll(advertise);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @PostMapping("queryAllByParam")
    public Result queryAllByParam(Integer pageNo, Integer pageSize, Advertise advertise) {
        return this.advertiseService.queryAllByParam(pageNo, pageSize, advertise);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @GetMapping("queryAllByParam")
    public Result queryAllByParamGet(Integer pageNo, Integer pageSize, Advertise advertise) {
        return this.advertiseService.queryAllByParam(pageNo, pageSize, advertise);
    }

    /**
     * 新增数据
     *
     * @param advertise 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Advertise insert(@RequestBody Advertise advertise) {
        this.advertiseService.insert(advertise);
        return advertise;
    }

    /**
     * 修改数据
     *
     * @param advertise 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Advertise update(@RequestBody Advertise advertise) {
        return this.advertiseService.update(advertise);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("deleteById")
    public boolean deleteById(Long id) {
        return this.advertiseService.deleteById(id);
    }
}